package com.ruoyi.shop.api.factory;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.shop.api.RemoteDrawalService;
import com.ruoyi.shop.api.RemoteShopService;
import com.ruoyi.shop.api.domain.CheDrawal;
import com.ruoyi.shop.api.domain.CheShop;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletResponse;
import java.util.concurrent.locks.Lock;

/**
 * 文件服务降级处理
 * 
 * @author ruoyi
 */
@Component
public class RemoteRemoteShopFallbackFactory implements FallbackFactory<RemoteShopService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteRemoteShopFallbackFactory.class);


    @Override
    public RemoteShopService create(Throwable throwable) {
        log.error("商户服务调用失败:{}", throwable.getMessage());
        return new RemoteShopService() {

            @Override
            public TableDataInfo list(CheShop cheShop, String source) {
                TableDataInfo tableDataInfo = new TableDataInfo();
                tableDataInfo.setMsg("获取商家列表失败: " + throwable.getMessage());
                tableDataInfo.setRows(new java.util.ArrayList<>());
                tableDataInfo.setTotal(0);
                return tableDataInfo;
            }

            @Override
            public AjaxResult phone(String perPhone, String source)
            {
                return AjaxResult.error("不存在"+perPhone+"这个邮箱的用户，请注册" + throwable.getMessage());
            }

            @Override
            public TableDataInfo listByStar(CheShop cheShop, String source) {
                TableDataInfo tableDataInfo = new TableDataInfo();
                tableDataInfo.setMsg("通过星级排序获取商家列表失败: " + throwable.getMessage());
                tableDataInfo.setRows(new java.util.ArrayList<>());
                tableDataInfo.setTotal(0);
                return tableDataInfo;
            }


            @Override
            public AjaxResult getInfo(Long shopId, String source) {
                return AjaxResult.error("通过id获取商户信息失败:" + throwable.getMessage());

            }

            @Override
            public AjaxResult add(CheShop cheShop, String source) {
                return AjaxResult.error("商户添加失败:" + throwable.getMessage());

            }

            @Override
            public AjaxResult edit(CheShop cheShop, String source) {
                return AjaxResult.error("商户修改失败:" + throwable.getMessage());

            }

            @Override
            public AjaxResult  remove(Long[] shopIds, String source) {
                return AjaxResult.error("商户删除失败:" + throwable.getMessage());

            }
        };
    }
}

